package com.jizhi.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jizhi.entity.Doctor;
import com.jizhi.service.DoctorService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 罗兆良
 * @since 2020-11-14
 */
@RestController
@RequestMapping("/doctor")
public class DoctorController {
    private static final Logger logger = LoggerFactory.getLogger(DoctorController.class);

    @Resource
    private DoctorService doctorService;

    @ApiOperation(value = "添加医生信息", notes = "根据页面传来的医生信息添加")
    @ApiImplicitParam(name = "doctor", value = "doctor", required = true, dataType = "Doctor")
    @RequestMapping(value = "doctor", method = RequestMethod.POST)
    public String getadd(@ModelAttribute Doctor doctor) {
        int count = doctorService.insert(doctor);
        if (count > 0) {
            return "添加成功";
        } else {
            return "添加失败";
        }
    }

    @ApiOperation(value = "查询医生信息分页", notes = "根据页面传来的分页信息查询医生信息")
    @GetMapping("/getAllDoctorPage")
    public List<Doctor> getAllDoctorPage(int current, Model model) {
        Page<Object> page = new Page<>(current, 2);
        List<Doctor> doctorList = doctorService.selectPage(page);
        logger.info("查询成功");
        return doctorList;
    }

}

